package com.ruoyi.jpbi.controller.jianshe;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpbi.domain.jianshe.Fomation;
import com.ruoyi.jpbi.service.FomationService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Auto zh
 * date 2019/10/16
 * 建设项目信息
 */
@Controller
@RequestMapping("/jianshe/fomation")

public class FomationController extends BaseController {
    private String prefix = "jpbi/jianshe/fomation";

    @Autowired
    private FomationService fomationService;


    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user() {
        return prefix + "/fomation";
    }

    @RequestMapping("/getFomationList")
    @ResponseBody
    public TableDataInfo getFomationList(Fomation fomation) {
        startPage();
        List<Fomation> getFomationList = fomationService.findAllFomation(fomation);
        return getDataTable(getFomationList);
    }

    /**
     * 查看公司
     */
    @RequestMapping("/detail")
    public String detail(String id, ModelMap mmap) {
        mmap.put("fomation", fomationService.findFomationone(id));
        return prefix + "/details";
    }




    @RequestMapping("/editFomation")
    public String editDepa(String id, ModelMap mmap) {
        Fomation fomation = fomationService.findFomationone(id);
        mmap.put("fomation", fomation);
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(Fomation fomation) {
        return toAjax(fomationService.updateFomation(fomation));
    }


    @GetMapping("/add")
    public String add(Fomation fomation) {
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Fomation fomation) {
        return toAjax(fomationService.insertFomation(fomation));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public int remove(String allFomationid)
    {
        List<String> fomationList = new ArrayList<String>();
        String[] arry = allFomationid.split(",");
        for(int i=0;i<arry.length;i++){
            fomationList.add(arry[i]);
        }
        return fomationService.deleteFomation(fomationList);
    }

    /**
     * 获取所有项目
     *
     * @return
     */
    @GetMapping("/getJspmRow")
    @ResponseBody
    public AjaxResult getDepRow() {
        List<Fomation> getFomationList = fomationService.findAllFomation(new Fomation());
        String[] strings = new String[getFomationList.size()];
        for (int i = 0; i < getFomationList.size(); i++) {
            strings[i] = getFomationList.get(i).getJspmName();
        }
        AjaxResult ajax = new AjaxResult();
        ajax.put("value", strings);
        return ajax;
    }

}
